package symbolTable;

import java.util.LinkedHashMap;
import java.util.Map;

public abstract class BaseScope implements Scope {
    private Scope enclosingScope;
    private Map<String, Symbol> symbols = new LinkedHashMap<String, Symbol>();

    public BaseScope(Scope enclosingScope) {
        this.enclosingScope = enclosingScope;
    }

    @Override
    public Scope getEnclosingScope() {
        return this.enclosingScope;
    }

    @Override
    public void define(Symbol symbol) {
        this.symbols.put(symbol.name, symbol);
        symbol.scope = this;
    }

    @Override
    public Symbol search(String name) {
        return this.symbols.get(name);
    }
}